package com.bdqn.t308.service;

import com.bdqn.t308.dao.SysUserDao;
import com.bdqn.t308.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service("userService")
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserDao sysUserDao;


    @Override
    public SysUser selectByPrimaryKey(int id) {

        return sysUserDao.selectByPrimaryKey(id);
    }

    @Transactional
    @Override
    public int deleteUserById(int id) {
        int result = 0;
        if(sysUserDao.deleteUserById(id)==1){
            result = 1;
            throw new RuntimeException();
        }
        return result;
    }

    @Override
    public int insertUser(SysUser sysUser) {
        int result = 0;
        if(sysUserDao.insertUser(sysUser)==1){
            result = 1;
            throw new RuntimeException("抛出异常测试事务回滚！");
        }
        return  result;
    }

    @Override
    public List<SysUser> findAllUserList(Map map) {
        return sysUserDao.findAllUserList(map);
    }
}
